import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/login.vue'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },

  {
    path: '/statistics',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/statistics/statistics.vue'),
        meta: { title: '数据统计', icon: 'nested' }
      }
    ]
  },

  {
    path: '/employee',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/employee/employee.vue'),
        meta: { title: '员工管理', icon: 'user' }
      }
    ]
  },

  {
    path: '/category',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/category/category.vue'),
        meta: { title: '分类管理', icon: 'tree' }
      }
    ]
  },

  {
    path: '/dishes',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/dishes/dishes.vue'),
        meta: { title: '菜品管理', icon: 'example' }
      }
    ]
  },

  {
    path: '/setmeal',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/setmeal/setmeal.vue'),
        meta: { title: '套餐管理', icon: 'form' }
      }
    ]
  },

  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/order/order.vue'),
        meta: { title: '订单管理', icon: 'table' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
